//
//  SecondViewController.m
//  UI12_Block传值
//
//  Created by TravelRound on 15/11/24.
//  Copyright © 2015年 TravelRound. All rights reserved.
//

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)dealloc
{
#warning block传值6 - 引用计数减1
    Block_release(_myBlock);
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor redColor];
    
    UIButton *buton = [UIButton buttonWithType:UIButtonTypeCustom];
    buton.frame = CGRectMake(50, 100, 80, 50);
    [buton addTarget:self action:@selector(butonAction:) forControlEvents:UIControlEventTouchUpInside];
    [buton setTitle:@"发春儿!" forState:UIControlStateNormal];
    buton.backgroundColor = [UIColor brownColor];
    [self.view addSubview:buton];
    
}

- (void)butonAction:(UIButton *)sender
{
#warning block传值5 - 调用block, 传递参数
    _myBlock([UIColor greenColor]);
}

- (void)sendBlock:(blockType)block str:(NSString *)str
{
    NSLog(@"%@", str);
    
//    block([UIColor greenColor]);
//    _myBlock = block;
#warning block传值4 - 将RootVC中定义的block空间拷贝到堆区, 防止释放
    _myBlock = Block_copy(block);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
